package com.module.share;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.widget.Toast;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.sina.weibo.SinaWeibo;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.tencent.qzone.QZone;
import cn.sharesdk.wechat.friends.Wechat;
import cn.sharesdk.wechat.moments.WechatMoments;

public class ShareAction {

	private Context context;

	private PlatformActionListener platformActionListener = new PlatformActionListener() {

		@Override
		public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

			Toast.makeText(context, "分享成功", Toast.LENGTH_SHORT).show();

		}

		@Override
		public void onError(Platform platform, int i, Throwable throwable) {

			Toast.makeText(context, "分享失败", Toast.LENGTH_SHORT).show();

		}

		@Override
		public void onCancel(Platform platform, int i) {

			Toast.makeText(context, "分享结束", Toast.LENGTH_SHORT).show();

		}

	};

    public ShareAction(Context context, String appKey){

        ShareSDK.initSDK(this.context = context, appKey);

    }

	public void shareQQ(final Context context,String title,String titleUrl,String text,int imgid) {

		QQ.ShareParams shareParams = new QQ.ShareParams();
		
		shareParams.setShareType(Platform.SHARE_WEBPAGE);

		shareParams.setTitle(title);

		shareParams.setUrl(titleUrl);

		shareParams.setText(text);

		shareParams.setImageData(BitmapFactory.decodeResource(context.getResources(), imgid));

		Platform platform = ShareSDK.getPlatform (QQ.NAME);

		platform.setPlatformActionListener(platformActionListener);

		platform.share(shareParams);

	}

	public void shareQzone(final Context context,String title,String titleUrl,String text,int imgid){

		QZone.ShareParams shareParams = new QZone.ShareParams();

		shareParams.setShareType(Platform.SHARE_WEBPAGE);

		shareParams.setTitle(title);

		shareParams.setTitleUrl(titleUrl);

		shareParams.setText(text);

		shareParams.setImageData(BitmapFactory.decodeResource(context.getResources(), imgid));

		shareParams.setSite(text);

		shareParams.setSiteUrl(titleUrl);

		Platform platform = ShareSDK.getPlatform (QZone.NAME);

		platform.setPlatformActionListener(platformActionListener);

		platform.share(shareParams);

	}

	public void shareWX(final Context context,String title,String titleUrl,String text,int imgid){

		Wechat.ShareParams shareParams = new Wechat.ShareParams();

		shareParams.setShareType(Platform.SHARE_WEBPAGE);

		shareParams.setTitle(title);

		shareParams.setUrl(titleUrl);

		shareParams.setText(text);

		shareParams.setImageData(BitmapFactory.decodeResource(context.getResources(), imgid));

		Platform platform = ShareSDK.getPlatform (Wechat.NAME);

		platform.setPlatformActionListener(platformActionListener);

		platform.share(shareParams);

	}

	public void shareSina(final Context context,String title,String titleUrl,String text,int imgid){

		SinaWeibo.ShareParams shareParams = new SinaWeibo.ShareParams();

		shareParams.setShareType(Platform.SHARE_WEBPAGE);

		shareParams.setTitle(title);

		shareParams.setUrl(titleUrl);

		shareParams.setText(text);

		shareParams.setImageData(BitmapFactory.decodeResource(context.getResources(), imgid));

		Platform platform = ShareSDK.getPlatform (SinaWeibo.NAME);

		platform.setPlatformActionListener(platformActionListener);

		platform.share(shareParams);

	}

	public void shareWXF(final Context context,String title,String titleUrl,String text,int imgid){

		WechatMoments.ShareParams shareParams = new WechatMoments.ShareParams();

		shareParams.setShareType(Platform.SHARE_WEBPAGE);

		shareParams.setTitle(title);

		shareParams.setUrl(titleUrl);

		shareParams.setText(text);
		
		shareParams.setImageData(BitmapFactory.decodeResource(context.getResources(), imgid));

		Platform platform = ShareSDK.getPlatform (WechatMoments.NAME);

		platform.setPlatformActionListener(platformActionListener);

		platform.share(shareParams);

	}

}
